package com.tszs.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tszs.biz.SmsConfigurationBiz;
import com.tszs.entity.SmsConfiguration;
import com.tszs.entity.SmsConfigurationExample;
import com.tszs.util.CallBack;
import com.tszs.util.Uuid;

import net.sf.json.JSONObject;

/**
 * @类名:SmsConfigurationController
 * @类描述：短信配置
 * @创建时间：2019-03-22 13:07:07
 * @创建人：王俊
 * @author Administrator
 *
 */
@Controller
public class SmsConfigurationController {
	/**
	 * @SmsConfigurationBiz
	 * @创建时间:201903-21 13:14:14
	 */
	@Autowired
	private SmsConfigurationBiz smsConfigurationBiz;

	/**
	 * @方法名:CashManagementTablePage
	 * @方法描述：提现管理分页 
	 * @创建时间：2019-03-22 13:07:07
	 * @创建人：王俊
	 * @author Administrator
	 *
	 */
	@RequestMapping("pc/admin/SmsConfigurationInsert")
	public void SmsConfigurationInsert(HttpServletRequest request,HttpServletResponse response) {
		SmsConfigurationExample example=new SmsConfigurationExample();
		List<SmsConfiguration> selectByExample=smsConfigurationBiz.selectByExample(example);
		SmsConfiguration example1=new SmsConfiguration();
		if(selectByExample.size()>0) {
			example1.setsId(Uuid.getUUID());
			example1.setsConten(request.getParameter("conten"));
			example1.setsPhoto(request.getParameter("phone"));
			example1.setsPass(request.getParameter("pass"));
			example1.setsTrues(request.getParameter("trues"));
			example1.setsCreateTime(Uuid.getTime());
			example1.setsStatic("0");
			example1.setAdminId(request.getSession().getAttribute("aId")+"");
			example1.setAdminUser(request.getSession().getAttribute("aUsername")+"");
			int c=smsConfigurationBiz.updateByExampleSelective(example1, example);
			if(c>0) {
				new CallBack().yes(response, "","");
			}else {
				new CallBack().no(response, "","");
			}
		}else {
			example1.setsId(Uuid.getUUID());
			example1.setsConten(request.getParameter("conten"));
			example1.setsPhoto(request.getParameter("phone"));
			example1.setsPass(request.getParameter("pass"));
			example1.setsTrues(request.getParameter("trues"));
			example1.setsStatic("0");
			example1.setsCreateTime(Uuid.getTime());
			example1.setAdminId(request.getSession().getAttribute("aId")+"");
			example1.setAdminUser(request.getSession().getAttribute("aUsername")+"");
			int c=smsConfigurationBiz.insertSelective(example1);
			if(c>0) {
				new CallBack().yes(response, "","");
			}else {
				new CallBack().no(response, "","");
			}
		}
	}
	/**
	 * @方法名:HomeRotaryMapPage
	 * @方法描述：前台图片轮播
	 * @创建时间：2019-03-22 13:07:07
	 * @创建人：王俊
	 * @author Administrator
	 *
	 */
	@RequestMapping("pc/admin/SmsConfigurationPage")
	public void findCommodityListPage(HttpServletRequest request,HttpServletResponse response) {
		response.setContentType("text/xml; charset=UTF-8");
		response.setContentType("text/html;charset=utf-8");
		int page = Integer.parseInt(request.getParameter("page"));
		int limit = Integer.parseInt(request.getParameter("limit"));
		SmsConfiguration example = new SmsConfiguration();
		example.setPage((page - 1) * limit);
		example.setLimit(limit);
		List<SmsConfiguration> selectByExample = smsConfigurationBiz.selectByExamplePage(example);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", selectByExample.size());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < selectByExample.size(); i++) {
			Map<String, Object> mapData = new HashMap<String, Object>();
			mapData.put("sPhoto",selectByExample.get(i).getsPhoto());
			mapData.put("sConten", selectByExample.get(i).getsConten());
			mapData.put("sTrues", selectByExample.get(i).getsTrues().equals("0")?"<a style='color:green'>开启</a>":"<a style='color:red'>删除</a>");
			mapData.put("sCreateTime", selectByExample.get(i).getsCreateTime());
			mapData.put("sPass", selectByExample.get(i).getsPass());
			mapData.put("AdminId", selectByExample.get(i).getAdminId());
			mapData.put("AdminUser", selectByExample.get(i).getAdminUser());
			list.add(mapData);
		}
		map.put("data", list);
		JSONObject json = JSONObject.fromObject(map);
		new CallBack().textObject(json, response);
	}
}
